package com.automannn.cloud.practice.loadbalancer;

import com.alibaba.fastjson.JSON;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author automannn
 * @Date 2023/5/5
 */
@SpringBootApplication
public class LoadbalancerApp {

    public static void main(String[] args) {
        ApplicationContext context= new SpringApplicationBuilder()
                .web(WebApplicationType.SERVLET)
                .properties("spring.config.name:loadbalancer")
                .sources(LoadbalancerApp.class)
                .build().run();

        LoadBalancerClient loadBalancerClient= context.getBean(LoadBalancerClient.class);
       ServiceInstance serviceInstance= loadBalancerClient.choose("automannn-provider");
        System.out.println(JSON.toJSONString(serviceInstance));
    }


}
